<{extend name="base" /}>
    <{block name="body" }>
        <style>html{font-size: 100px}</style>
        <div class="layui-body ">
            <div class="layui-tab layui-tab-brief">
                <ul class="layui-tab-title">
                    <li class=""><a href="<{:url('admin/view/index')}>">已添加列表</a></li>
                    <li class=""><a href="<{:url('admin/view/create',['style_id'=>1])}>">样式一</a></li>
                    <li class=""><a href="<{:url('admin/view/create',['style_id'=>2])}>">样式二</a></li>
                    <li class="layui-this"><a href="<{:url('admin/view/create',['style_id'=>3])}>">样式三</a></li>
                    <li class=""><a href="<{:url('admin/view/create',['style_id'=>4])}>">样式四</a></li>
                    <li class=""><a href="<{:url('admin/view/create',['style_id'=>5])}>">样式五</a></li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show" id="app">
                        <div class="left">
                            <form class="layui-form" method="post" action="<{:url('admin/view/save')}>">
                                <input type="hidden" name="style" value="3">
                                <{php}>
                                if(request()->action() == 'edit'){
                                    echo '<input type="hidden" name="type" value="edit">';
                                    echo '<input type="hidden" name="id" value="'.request()->get('id').'">';
                                }
                                <{/php}>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">标题</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="content[title]" id="title" lay-verify="required" v-model='title' placeholder="{用此符号可飘红，支持多个} 必须成对书写"
                                            class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">缩略图</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="content[thumb]" lay-verify="required" v-model='thumb' class="layui-input layui-input-inline" id="mythumb">
                                        <input type="file" name="file" class="layui-upload-file">
                                    </div>
                                </div>
                                <div class="layui-form-item layui-form-text">
                                    <label class="layui-form-label">描述</label>
                                    <div class="layui-input-block">
                                        <textarea name="content[desc]" lay-verify="required" required placeholder="{用此符号可飘红，支持多个} 必须成对书写"
                                            class="layui-textarea" v-model='desc'></textarea>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">链接</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="content[url]" v-model='url' required lay-verify="required|url" placeholder="例如：http://baidu.com" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">公司名称</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="content[company]" v-model='company' lay-verify="required" placeholder="例如：百度中国有限公司" class="layui-input">
                                    </div>
                                </div>


                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="right" id="baidu-search">
                            <link rel="stylesheet" href="/baidu/css/style.css" />
                                <div class="c-container ec_resitem ec-new2  ec_wise_pp ec_adv_last">
                                    <div>
                                        <a class="c-blocka ec_title " :href="url">
                                            <h3 class="c-title c-color-link c-gap-top-small c-gap-bottom-small c-line-clamp3" v-html="Ctitle"></h3>
                                        </a>
                                        <div class="c-row c-gap-top-small">
                                            <div class="c-span4">
                                                <a :href="url" class="ec-left-img c-blocka ec-mt-2062 ">
                                                    <div class="c-img c-img-s">
                                                        <img :src="thumb">
                                                    </div>
                                                </a>
                                            </div>
                                            <div class="c-span8 ec-span8-desc">
                                                <div>
                                                    <a :href="url" class="c-blocka ">
                                                        <p class="c-line-clamp5 c-color " v-html="Cdesc"></p>
                                                    </a>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="c-showurl c-line-clamp1 c-gap-top-small">
                                            <span class="ec_urlbtn"></span>
                                            <div class="ec_urlline">
                                                <a :href="url" class="ec-showurl-line " cid="105">
                                                    <span class="c-showurl" v-html="company"></span>
                                                </a>
                                                <span class="c-gap-left ec-vicon">
                                                    <img src=""
                                                        class="c-icon ec-icon-blue ec-icon-size-small c-gap-right-small" />
                                                </span>
                                                <span class="c-gap-left ec-tuiguang">广告</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

<{/block}>
<{block name="script" }>
                <style type="text/css">
                    .left,
                    .right {
                        float: left;
                    }

                    .left {
                        width: 60%;
                    }

                    .right {
                        height: 550px;
                        margin-left: 60px;
                        width: 300px;
                        border: 2px solid #ccc;
                        border-radius: 20px;
                        padding: 20px;
                        background: #f1f1f1;
                        box-shadow: 1px 2px #eeeeee5c;
                    }
                </style>
                <script src="/static/js/vue.js"></script>
                <script type="text/javascript">
                    var vue = new Vue({
                        el: "#app",
                        data: {
                            title: '',
                            desc: '',
                            url:'',
                            company:'百度中国有限公司',
                            thumb: 'http://iph.href.lu/80x80'
                        },
                        computed: {
                            Ctitle: function () {
                                if (this.title == '') {
                                    return '<em>百度</em>中国有限公司';
                                }
                                return this.title.replace(/{/g, '<em>').replace(/}/g, '</em>');
                            },
                            Cdesc: function () {
                                if (this.desc == '') {
                                    return '<em>用此符号可飘红，支持多个</em>必须成对书写<em>用此符号可飘红，支持多个</em> 必须成对书写<em>用此符号可飘红，支持多个</em>必须成对书写...';
                                }
                                return this.desc.replace(/{/g, '<em>').replace(/}/g, '</em>');
                            }

                        }
                    });

                    <{php}>
                        if(request()->action() == 'edit'){

                            echo "vue.title = '".$data['content']['title']."';";
                            echo "vue.desc = '".$data['content']['desc']."';";
                            echo "vue.company = '".$data['content']['company']."';";
                            echo "vue.url = '".$data['content']['url']."';";
                            echo "vue.thumb = '".$data['content']['thumb']."';";

                        }
                    <{/php}>


                    $(function () {
                        layui.upload({
                            url: "/api/upload/upload",
                            type: 'image',
                            ext: 'jpg|png|gif|bmp',
                            success: function (data) {
                                if (data.error === 0) {
                                    document.getElementById('mythumb').value = data.url;
                                    vue.Bsrc = data.url; //映射到vue
                                    $(".c-img>img").attr('src', data.url);
                                } else {
                                    layer.msg(data.message);
                                }
                            }
                        });
                    });
                </script>
                <{/block}>
